using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace SharepointListMigrator
{
    /// <summary>
    /// Implementation for migrating the specifics of the News list
    /// </summary>
    public class NewsListMigratorAlgorithm : IListMigratorAlgorithm
    {

        public bool MoveAttachments
        {
            get { return true; }
        }
        public string SourceViewGuid
        {
            get { return "{0C013B6C-016D-4CD9-8C6D-FC4C3BAA448E}"; }
        }

        public string SourceListName
        {
            get { return "Announcements"; }
        }

        public string DestinationViewGuid
        {
            get { return string.Empty; }
        }

        public string DestinationListName
        {
            get { return "News"; }
        }

        public int NumberOfItemsToMigrate
        {
            get { return 10; }
        }

        public string GenericListName
        {
            get { return "News"; }
        }

        /// <summary>
        /// returns the XML for the specific field updates
        /// </summary>
        public string BuildItemUpdateXml(XmlNode item)
        {
            if (item == null)
                throw new ArgumentNullException("The parameter 'item' cannot be null.");

            //note that we use the 'Published' field  because u cannot update 'Created' or 'Modified' via the sharept web services
            return string.Format("<Field Name='ID'>New</Field>" +
                                    "<Field Name='Title'>{0}</Field>" +
                                    "<Field Name='Body'>{1}</Field>" +
                                    "<Field Name='Expires'>{2}</Field>" +
                                    "<Field Name='More_x0020_Information'>{3}</Field>" +
                                    "<Field Name='Published'>{4}</Field>",
                                 item.Attributes["ows_Title"] == null ? string.Empty : System.Web.HttpUtility.HtmlEncode(item.Attributes["ows_Title"].Value),
                                 item.Attributes["ows_Body"] == null ? string.Empty : System.Web.HttpUtility.HtmlEncode(item.Attributes["ows_Body"].Value),
                                 item.Attributes["ows_Expires"] == null ? string.Empty : item.Attributes["ows_Expires"].Value,
                                 item.Attributes["ows_More_x0020_Information"] == null ? string.Empty : System.Web.HttpUtility.HtmlEncode(item.Attributes["ows_More_x0020_Information"].Value),
                                 item.Attributes["ows_Created"] == null ? string.Empty : item.Attributes["ows_Created"].Value);

        }
    }
}
